| Conditions | 1 |
| Paths | 1 |
| Total Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import chai from 'chai'; |
||
| 17 | describe(`[module] utils`, function() { |
||
| 18 | describe(`[method] kill`, function() { |
||
| 19 | let sandbox; |
||
| 20 | beforeEach(function() { |
||
| 21 | sandbox = sinon.sandbox.create(); |
||
| 22 | }); |
||
| 23 | afterEach(function() { |
||
| 24 | sandbox.restore(); |
||
| 25 | }); |
||
| 26 | it(`should call process.exit with an negative value`, mute(function() { |
||
| 27 | let exit = sandbox.stub(process, `exit`); |
||
| 28 | let message = `Some error message`; |
||
| 29 | utils.kill(new Error(message)); |
||
| 30 | expect(exit).to.have.been.calledOnce; |
||
| 31 | expect(exit.getCall(0).args[0]).to.be.below(0); |
||
| 32 | })); |
||
| 33 | }); |
||
| 34 | describe(`[method] login`, function() { |
||
| 35 | let sandbox; |
||
| 36 | beforeEach(function() { |
||
| 37 | sandbox = sinon.sandbox.create(); |
||
| 38 | }) |
||
| 39 | afterEach(function() { |
||
| 40 | sandbox.restore(); |
||
| 41 | }); |
||
| 42 | it(`should resolve if login is successfull`, function() { |
||
| 43 | let login = sinon.stub(cgapi, `login`, function() {return Promise.resolve(true)}); |
||
| 44 | let get = sinon.stub(configure, `get`, function(property) {return Promise.resolve(property);}); |
||
| 45 | let log = utils.login(`username`, `password`) |
||
| 46 | let calls = log.then(function() { |
||
| 47 | expect(login).to.have.been.calledOnce; |
||
| 48 | expect(get).to.have.been.calledTwice; |
||
| 49 | return Promise.resolve(true); |
||
| 50 | }); |
||
| 51 | return Promise.all([ |
||
| 52 | expect(log).to.eventually.be.fullfilled, |
||
| 53 | calls |
||
| 54 | ]); |
||
| 55 | }); |
||
| 56 | it(`should reject after 3 tries if authentication failed`, mute(function() { |
||
| 57 | let login = sandbox.stub(cgapi, `login`, function() { |
||
| 58 | return Promise.resolve({ |
||
| 59 | "error": new Error(`Cannot authenticate`) |
||
| 60 | }); |
||
| 61 | }); |
||
| 62 | get = sandbox.stub(configure, `get`, function(property) {return Promise.resolve(property);}); |
||
| 63 | let log = utils.login(`username`, `password`) |
||
| 64 | let calls = log.catch(function() { |
||
| 65 | expect(login).to.have.been.calledThrice; |
||
| 66 | return Promise.resolve(true); |
||
| 67 | }); |
||
| 68 | return Promise.all([ |
||
| 69 | expect(log).to.eventually.be.rejected, |
||
| 70 | calls |
||
| 71 | ]); |
||
| 72 | })); |
||
| 73 | }); |
||
| 74 | describe(`[method] tests`, function() { |
||
| 75 | let sandbox; |
||
| 76 | beforeEach(function() { |
||
| 97 |